package com.rwb.springboot.controller;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * Created by ruwenbo on 2018/4/16.
 */
@RestController
public class HtmlRestController {

    @RequestMapping({"/html/demo"})
    @ResponseBody
    public String htmlCode() {
        return "hello World";
    }

    @RequestMapping({"/html/demo/{param}"})
    @ResponseBody
    public String htmlPathVariable(@PathVariable String param) {
        return "hello World  and param is :" + param;
    }

    @RequestMapping({"/html/demo2"})
    @ResponseBody
    public String htmlRequestParam(@RequestParam String param) {
        return "This is test requestParam  and param is :" + param;
    }

    @RequestMapping("/html/demo/header")
    @ResponseBody
    public String htmlHeader(@RequestHeader(value = "Accept") String header) {
        return "This is test RequestHeader and header is :" + header;
    }

    @RequestMapping("/html/demo/responseEntity")
    public ResponseEntity<String> htmlResponseEntity() {

        HttpHeaders headers = new HttpHeaders();

        headers.put("myHeader", Arrays.asList("MyHeader"));

        return new ResponseEntity<>("This is test ResponseEntity", headers, HttpStatus.OK);
    }

}
